<?php

namespace App\Models\CacheModel;

use App\Models\Api\BaseCache;
use AstroTool\Cache\CacheManage;

class ZlcrAstrConsultActiveReplyRecord extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zlcr_astr_consult_active_reply_record';

    protected $cacheModel = 'astr_admin.astr_consult_active_reply_record';

    public function getActiveReplyData()
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel)
            ->getDataAndSet(function ()
            {
                try
                {
                    $dataList = $this->whereTime('create_time', '-1 hours')->column('count(*)', 'astr_id');
                    $data = [0 => 0];
                    foreach ($dataList as $astrId => $num)
                    {
                        if ($num)
                        {
                            $data[$astrId] = $num;
                        }
                    }
                    return $data;
                }
                catch (\Exception $e)
                {
                    \think\Log::write(__CLASS__ . ' => ' . __FUNCTION__ . '()异常：' . $e->getMessage() . '失败信息：' . $e->getFile() . ':' . $e->getLine(), 'error', true);
                    $data = [0 => 0];
                }
                return $data;
            });
        unset($data[0]);

        return $data ? array_map('intval', $data) : [];
    }
}
